package com.ctz.commonframe.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by 陈堂正 on 2017/2/24.
 */

public class ImageView_16_9 extends ImageView{
    public ImageView_16_9(Context context) {
        super(context);
    }

    public ImageView_16_9(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ImageView_16_9(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

        int childWidthSize = getMeasuredWidth();
        //宽度/高度 = 16/9
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
        heightMeasureSpec = widthMeasureSpec * 9 /16;
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
